R Markdown

This is an result for the gene singatures as well as assigned cell type for each cluster based on Danaher et al.

knitr::opts_chunk$set(cache=TRUE)
for( i in 1:length(mean_score[1,])){
print(visualize_me(mean_score[,i],cell_list[i],analysis_results$tsne[c("TSNE.1","TSNE.2")],title=names(cell_list)[i]))
# really hard to see
#print(plot(mean_score[,i],type = "h",xlab="Single Cell",ylab=colnames(mean_score)[i]))
h <-hist(mean_score[,i],plot = FALSE)

print(plot(h, freq = TRUE, labels =TRUE, ylim=c(0, 1.2*max(h$counts)),main=c(names(cell_list)[i]," Score per Single Cell"),xlab=paste(sep=" ",names(cell_list)[i],"Expression Level"),ylab="Numbers of cells"))
}

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL

## NULL
sig_plot <- visualize_clusters(cluster_tsne$cell_type,cluster_tsne[c("TSNE.1","TSNE.2")],title="Danaher cell-type labels",legend_anno= sort(unique(cluster_tsne[,"name_type"])))
#sig_plot <-sig_plot +scale_fill_discrete(name="Cell Type",
#                         breaks=unique(cluster_assignment$cell_type),
#                         labels=sapply(unique(cluster_assignment$cell_type),function(x) names(cell_list[x])))

print(sig_plot)

counter <-1
colnames(score_by_cluster) <- names(cell_list)
apply(score_by_cluster, 1,function(x) {plot(x,ylab="mean expression level",xlab="cell type", main=c("Cluster",counter))
text(x, names(cell_list), cex=0.6, pos=4, col="red")
counter <<- counter + 1})

##  [1]  2  3  4  5  6  7  8  9 10 11

This is a gene exprssion profile for each cell signature for each custer.The top expressed gene signatures of the majority of the cluster are well reprsented (All signatures are expressed among 80% to 90% of the cells in each cluster, except in Cluster 4,5 and 9)

top_sig <- data.frame(t(sapply(unique(all_type_expr_table$Cluster),function(x){ all_type_expr_table[all_type_expr_table$Cluster == x,][which(all_type_expr_table$precent_count[all_type_expr_table$Cluster == x] == max(all_type_expr_table$precent_count[all_type_expr_table$Cluster == x])),] })))
top_sig$Signature <-lapply(top_sig$Signature,function(y){paste(y)})
cbind(top_sig, cluster_assignment = cluster_type[,"name_type"])
##    Cluster               Signature Barcode_count total_Exp avg_non_zero
## 1        1             Macrophages           832      5571     5.435122
## 2        2                 T_cells         11147    103645     4.072815
## 3        3                 T_cells         16150    139048     3.920711
## 4        4             Neutrophils           546      1239     1.998387
## 5        5             Macrophages            34       177     5.205882
## 6        6                 B_cells          2187     21816     4.088456
## 7        7         Cytotoxic_cells          5882    283649     7.918954
## 8        8         Cytotoxic_cells           183      1727     7.256303
## 9        9             Macrophages            10        16          1.6
## 10  10, 10 Macrophages, Mast_cells          1, 1      1, 9         1, 3
##              SD cell_total_count precent_count cluster_assignment
## 1      3.699126              963      86.39668               CD45
## 2      3.460277            11716      95.14339            T_cells
## 3      3.382486            17068      94.62151            T_cells
## 4      2.303681             1768      30.88235               CD45
## 5       3.20775               75      45.33333        Macrophages
## 6      3.623682             2282      95.83699            B_cells
## 7      5.924657             5900      99.69492    Cytotoxic_cells
## 8      4.297662              202      90.59406    Cytotoxic_cells
## 9      1.897367               25            40        Macrophages
## 10 NA, 3.464102             1, 1      100, 100         Mast_cells
top_sig
##    Cluster               Signature Barcode_count total_Exp avg_non_zero
## 1        1             Macrophages           832      5571     5.435122
## 2        2                 T_cells         11147    103645     4.072815
## 3        3                 T_cells         16150    139048     3.920711
## 4        4             Neutrophils           546      1239     1.998387
## 5        5             Macrophages            34       177     5.205882
## 6        6                 B_cells          2187     21816     4.088456
## 7        7         Cytotoxic_cells          5882    283649     7.918954
## 8        8         Cytotoxic_cells           183      1727     7.256303
## 9        9             Macrophages            10        16          1.6
## 10  10, 10 Macrophages, Mast_cells          1, 1      1, 9         1, 3
##              SD cell_total_count precent_count
## 1      3.699126              963      86.39668
## 2      3.460277            11716      95.14339
## 3      3.382486            17068      94.62151
## 4      2.303681             1768      30.88235
## 5       3.20775               75      45.33333
## 6      3.623682             2282      95.83699
## 7      5.924657             5900      99.69492
## 8      4.297662              202      90.59406
## 9      1.897367               25            40
## 10 NA, 3.464102             1, 1      100, 100
all_type_expr_table
##     Cluster        Signature Barcode_count total_Exp avg_non_zero       SD
## 1         1          B_cells            28        55     1.527778 2.360219
## 2         1             CD45           480      1681     3.502083 3.303695
## 3         1      CD8_T_cells            39       114     2.651163 2.869243
## 4         1  Cytotoxic_cells           303      1376     3.192575 4.026371
## 5         1    Exhausted_CD8           161       284     1.690476 1.945215
## 6         1      Macrophages           832      5571     5.435122 3.699126
## 7         1      Neutrophils           311       654     1.826816 2.112563
## 8         1 NK_CD56dim_cells            21        21     1.000000 0.000000
## 9         1         NK_cells             6        25     3.571429 3.207135
## 10        1          T_cells           143       638     2.913242 2.991848
## 11        1        Th1_cells             9        15     1.666667 2.000000
## 12        1             Treg             2         2     1.000000 0.000000
## 13        2          B_cells           340       795     2.048969 2.444246
## 14        2             CD45          3646      9692     2.658256 2.807309
## 15        2      CD8_T_cells          2649     11130     3.312500 3.172329
## 16        2  Cytotoxic_cells          7866    112444     5.236042 4.343983
## 17        2               DC            42        60     1.428571 1.563967
## 18        2    Exhausted_CD8          1778      3240     1.724321 1.991355
## 19        2      Macrophages           282       408     1.441696 1.613098
## 20        2       Mast_cells             3        10     3.333333 4.041452
## 21        2      Neutrophils            19        25     1.315789 1.376494
## 22        2 NK_CD56dim_cells           173       268     1.540230 1.778514
## 23        2         NK_cells           402      1033     2.275330 2.524312
## 24        2          T_cells         11147    103645     4.072815 3.460277
## 25        2        Th1_cells           305       408     1.337705 1.393378
## 26        2             Treg            84       163     1.940476 2.213601
## 27        3          B_cells           207       449     1.918803 2.297094
## 28        3             CD45          4863     11961     2.459593 2.661324
## 29        3      CD8_T_cells          4141     21377     3.926708 3.351746
## 30        3  Cytotoxic_cells          5187     13357     2.174345 2.566798
## 31        3               DC             8         8     1.000000 0.000000
## 32        3    Exhausted_CD8          1001      1495     1.477273 1.644003
## 33        3      Macrophages           248       321     1.294355 1.309436
## 34        3       Mast_cells             4        16     4.000000 3.464102
## 35        3      Neutrophils            31        38     1.187500 1.060660
## 36        3 NK_CD56dim_cells           137       173     1.262774 1.232346
## 37        3         NK_cells            28        51     1.593750 1.881307
## 38        3          T_cells         16150    139048     3.920711 3.382486
## 39        3        Th1_cells            64        82     1.281250 1.278252
## 40        3             Treg            30        55     1.833333 2.166888
## 41        4          B_cells            58       149     2.328125 2.678869
## 42        4             CD45           265       585     2.207547 2.528313
## 43        4      CD8_T_cells            41        94     2.136364 2.445603
## 44        4  Cytotoxic_cells           387      1881     3.329204 3.853424
## 45        4               DC             1         1     1.000000       NA
## 46        4    Exhausted_CD8            99       151     1.480392 1.657449
## 47        4      Macrophages           391       769     1.835322 2.167417
## 48        4      Neutrophils           546      1239     1.998387 2.303681
## 49        4 NK_CD56dim_cells             7        19     2.714286 2.927700
## 50        4         NK_cells             9        11     1.000000 0.000000
## 51        4          T_cells           259       719     2.152695 2.487936
## 52        4        Th1_cells             8         8     1.000000 0.000000
## 53        5             CD45             2         2     1.000000 0.000000
## 54        5      CD8_T_cells             1         7     7.000000       NA
## 55        5  Cytotoxic_cells            21       147     3.769231 4.836601
## 56        5      Macrophages            34       177     5.205882 3.207750
## 57        5         NK_cells             1         1     1.000000       NA
## 58        5          T_cells             6        35     3.181818 3.027150
## 59        5        Th1_cells             1         1     1.000000       NA
## 60        6          B_cells          2187     21816     4.088456 3.623682
## 61        6             CD45           539      1249     2.317254 2.580579
## 62        6      CD8_T_cells            59       149     2.191176 2.638732
## 63        6  Cytotoxic_cells           377      2065     3.542024 4.473811
## 64        6    Exhausted_CD8            59        77     1.305085 1.329431
## 65        6      Macrophages            82       116     1.397590 1.592205
## 66        6       Mast_cells             1         1     1.000000       NA
## 67        6      Neutrophils            20        20     1.000000 0.000000
## 68        6 NK_CD56dim_cells            20        20     1.000000 0.000000
## 69        6         NK_cells             5         5     1.000000 0.000000
## 70        6          T_cells           306      1375     2.846791 3.010584
## 71        6        Th1_cells            16        16     1.000000 0.000000
## 72        6             Treg             1         1     1.000000       NA
## 73        7          B_cells            74       270     2.477064 3.065931
## 74        7             CD45          2104      6099     2.898764 2.947910
## 75        7      CD8_T_cells          2505     10733     3.266281 3.112894
## 76        7  Cytotoxic_cells          5882    283649     7.918954 5.924657
## 77        7               DC             1         1     1.000000       NA
## 78        7    Exhausted_CD8           996      1769     1.662594 1.924216
## 79        7      Macrophages            92       151     1.641304 2.019583
## 80        7      Neutrophils            12        12     1.000000 0.000000
## 81        7 NK_CD56dim_cells           414       713     1.646651 1.908156
## 82        7         NK_cells          1052      2835     2.304878 2.589437
## 83        7          T_cells          3853     33071     4.141641 3.509735
## 84        7        Th1_cells           848      1558     1.837264 2.108493
## 85        7             Treg             7         7     1.000000 0.000000
## 86        8          B_cells           132       635     3.489011 3.303671
## 87        8             CD45            16        29     1.812500 2.227667
## 88        8      CD8_T_cells             6        18     3.000000 3.098387
## 89        8  Cytotoxic_cells           183      1727     7.256303 4.297662
## 90        8    Exhausted_CD8             3         3     1.000000 0.000000
## 91        8      Macrophages            59       170     2.575758 2.700773
## 92        8      Neutrophils             8         8     1.000000 0.000000
## 93        8 NK_CD56dim_cells             1         1     1.000000       NA
## 94        8         NK_cells             1         1     1.000000       NA
## 95        8          T_cells            35       176     3.591837 3.174891
## 96        8        Th1_cells             2         2     1.000000 0.000000
## 97        9          B_cells             1         1     1.000000       NA
## 98        9  Cytotoxic_cells             4         4     1.000000 0.000000
## 99        9      Macrophages            10        16     1.600000 1.897367
## 100       9          T_cells             2         2     1.000000 0.000000
## 101      10      Macrophages             1         1     1.000000       NA
## 102      10       Mast_cells             1         9     3.000000 3.464102
##     cell_total_count precent_count
## 1                963    2.90758048
## 2                963   49.84423676
## 3                963    4.04984424
## 4                963   31.46417445
## 5                963   16.71858775
## 6                963   86.39667705
## 7                963   32.29491173
## 8                963    2.18068536
## 9                963    0.62305296
## 10               963   14.84942887
## 11               963    0.93457944
## 12               963    0.20768432
## 13             11716    2.90201434
## 14             11716   31.11983612
## 15             11716   22.61010584
## 16             11716   67.13895527
## 17             11716    0.35848412
## 18             11716   15.17582793
## 19             11716    2.40696483
## 20             11716    0.02560601
## 21             11716    0.16217139
## 22             11716    1.47661318
## 23             11716    3.43120519
## 24             11716   95.14339365
## 25             11716    2.60327757
## 26             11716    0.71696825
## 27             17068    1.21279588
## 28             17068   28.49191469
## 29             17068   24.26177642
## 30             17068   30.39020389
## 31             17068    0.04687134
## 32             17068    5.86477619
## 33             17068    1.45301148
## 34             17068    0.02343567
## 35             17068    0.18162644
## 36             17068    0.80267167
## 37             17068    0.16404968
## 38             17068   94.62151394
## 39             17068    0.37497071
## 40             17068    0.17576752
## 41              1768    3.28054299
## 42              1768   14.98868778
## 43              1768    2.31900452
## 44              1768   21.88914027
## 45              1768    0.05656109
## 46              1768    5.59954751
## 47              1768   22.11538462
## 48              1768   30.88235294
## 49              1768    0.39592760
## 50              1768    0.50904977
## 51              1768   14.64932127
## 52              1768    0.45248869
## 53                75    2.66666667
## 54                75    1.33333333
## 55                75   28.00000000
## 56                75   45.33333333
## 57                75    1.33333333
## 58                75    8.00000000
## 59                75    1.33333333
## 60              2282   95.83698510
## 61              2282   23.61963190
## 62              2282    2.58545136
## 63              2282   16.52059597
## 64              2282    2.58545136
## 65              2282    3.59333918
## 66              2282    0.04382121
## 67              2282    0.87642419
## 68              2282    0.87642419
## 69              2282    0.21910605
## 70              2282   13.40929010
## 71              2282    0.70113935
## 72              2282    0.04382121
## 73              5900    1.25423729
## 74              5900   35.66101695
## 75              5900   42.45762712
## 76              5900   99.69491525
## 77              5900    0.01694915
## 78              5900   16.88135593
## 79              5900    1.55932203
## 80              5900    0.20338983
## 81              5900    7.01694915
## 82              5900   17.83050847
## 83              5900   65.30508475
## 84              5900   14.37288136
## 85              5900    0.11864407
## 86               202   65.34653465
## 87               202    7.92079208
## 88               202    2.97029703
## 89               202   90.59405941
## 90               202    1.48514851
## 91               202   29.20792079
## 92               202    3.96039604
## 93               202    0.49504950
## 94               202    0.49504950
## 95               202   17.32673267
## 96               202    0.99009901
## 97                25    4.00000000
## 98                25   16.00000000
## 99                25   40.00000000
## 100               25    8.00000000
## 101                1  100.00000000
## 102                1  100.00000000

A closer look at gene composition in Cluster 7 (used as an example). PCA is performed for Cytotoxic_cells to determine which gene(s) “drive” the signature. Excluding cell with only zeor counts. Furhter Normalization is required - Need to work on that.

knitr::opts_chunk$set(cache=TRUE)
all_list_gene<- get_signature_matrix (all_type_expr,7,"Cytotoxic_cells")
alg_pca<-prcomp(all_list_gene)
summary(alg_pca)
## Importance of components%s:
##                           PC1    PC2    PC3    PC4     PC5    PC6     PC7
## Standard deviation     8.7936 5.8285 5.2541 4.9899 4.48346 3.9861 3.67443
## Proportion of Variance 0.3421 0.1503 0.1221 0.1102 0.08894 0.0703 0.05974
## Cumulative Proportion  0.3421 0.4925 0.6146 0.7248 0.81371 0.8840 0.94376
##                            PC8     PC9 PC10
## Standard deviation     3.45742 0.87048    0
## Proportion of Variance 0.05289 0.00335    0
## Cumulative Proportion  0.99665 1.00000    1
plot(alg_pca, type = "l")

alg_pca
## Standard deviations (1, .., p=10):
##  [1] 8.7935689 5.8285039 5.2541072 4.9899298 4.4834628 3.9860782 3.6744318
##  [8] 3.4574179 0.8704766 0.0000000
## 
## Rotation (n x k) = (10 x 10):
##                          PC1          PC2          PC3          PC4
## ENSG00000172543 -0.050876357  0.064450843 -0.266535196  0.935181890
## ENSG00000115523  0.962513591  0.187070782  0.146121342  0.063901415
## ENSG00000145649  0.048840454 -0.044780733 -0.133907730  0.152381261
## ENSG00000100453  0.088441188 -0.125541620 -0.132864708 -0.026512722
## ENSG00000100450  0.050641375 -0.044374122  0.163583203  0.182051154
## ENSG00000180644  0.101475027  0.341239991 -0.856091055 -0.245492591
## ENSG00000105374  0.211639919 -0.904619540 -0.306574935 -0.030423399
## ENSG00000134539  0.055595212 -0.079572725  0.135507816  0.055429245
## ENSG00000111796  0.005285606  0.001572834  0.004616799  0.004609626
## ENSG00000213809  0.000000000  0.000000000  0.000000000  0.000000000
##                           PC5          PC6          PC7         PC8
## ENSG00000172543  0.1345975494  0.013434041 -0.148839962 -0.08478107
## ENSG00000115523  0.0811692159  0.058702898 -0.046504283  0.03015375
## ENSG00000145649 -0.0400913105 -0.058931103  0.818109881  0.52922009
## ENSG00000100453 -0.0152375302 -0.936348129 -0.216648707  0.18472484
## ENSG00000100450 -0.9657662849  0.007425380 -0.051226751 -0.01260386
## ENSG00000180644 -0.2006149910  0.049925164  0.034944441 -0.19007970
## ENSG00000105374  0.0002883222  0.188946442 -0.059107424 -0.05245696
## ENSG00000134539  0.0215394720 -0.278940546  0.502046872 -0.79905868
## ENSG00000111796  0.0063748678 -0.009826444  0.007316746 -0.01304229
## ENSG00000213809  0.0000000000  0.000000000  0.000000000  0.00000000
##                           PC9 PC10
## ENSG00000172543 -0.0036562987    0
## ENSG00000115523 -0.0055591476    0
## ENSG00000145649  0.0003209876    0
## ENSG00000100453 -0.0046448304    0
## ENSG00000100450  0.0046487401    0
## ENSG00000180644  0.0030463462    0
## ENSG00000105374  0.0034637069    0
## ENSG00000134539 -0.0180269393    0
## ENSG00000111796  0.9997830720    0
## ENSG00000213809  0.0000000000    1
loadings <- alg_pca$rotation
sdev <- alg_pca$sdev
var_coord <- var.cor <- t(apply(loadings, 1, var_cor_func, sdev))

test_1 <- all_type_expr[ all_type_expr$Cluster==7 & all_type_expr$Signature =="Cytotoxic_cells",] %>% group_by(Gene,Signature) %>% summarise(count=n_distinct(Barcode),EXP_mean=mean(as.numeric(Expression)),SD_mean = sd(as.numeric(Expression)),Abs_Exp=sum(as.numeric(Expression)))
test_1
## # A tibble: 10 x 6
## # Groups:   Gene [?]
##               Gene       Signature count  EXP_mean  SD_mean Abs_Exp
##             <fctr>          <fctr> <int>     <dbl>    <dbl>   <dbl>
##  1 ENSG00000100450 Cytotoxic_cells  4090  6.596822 3.684426   26981
##  2 ENSG00000100453 Cytotoxic_cells  4872  7.262931 3.795214   35385
##  3 ENSG00000105374 Cytotoxic_cells  5845  9.955004 5.375419   58187
##  4 ENSG00000111796 Cytotoxic_cells   411  2.289538 2.588221     941
##  5 ENSG00000115523 Cytotoxic_cells  5719 14.044938 8.436785   80323
##  6 ENSG00000134539 Cytotoxic_cells  1395  2.318280 2.553963    3234
##  7 ENSG00000145649 Cytotoxic_cells  4982  6.480329 3.599158   32285
##  8 ENSG00000172543 Cytotoxic_cells  4851  5.998557 3.573586   29099
##  9 ENSG00000180644 Cytotoxic_cells  3647  4.718124 3.577074   17207
## 10 ENSG00000213809 Cytotoxic_cells     7  1.000000 0.000000       7